import request from "../../utils/request"

// pages/withdrawDeposit/withdrawDeposit.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    withdrawalList: [],
    total: 0,
    current: 1,

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    request({
      url: '/agent/withdraw/records',
      data: {
        pageNum: this.data.current,
      }
    }).then(res => {
      if (res.data.code == 200) {
        if (res.data.data.total == 0) {
          wx.showToast({
            title: '暂无数据~',
            icon: 'none'
          })
        } else {
          wx.showToast({
            title: '获取数据成功~',
            icon: 'none'
          })
        }
        this.setData({
          withdrawalList: res.data.data.records,
          total: res.data.data.total,
        })
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    const that = this;
    if (that.data.withdrawalList.length >= that.data.total) {
      wx.showToast({
        icon: "none",
        title: '噢噢，到底了~~',
        duration: 3500
      })
      that.setData({
        show_noMore: true
      })
    } else {
      that.setData({
        current: that.data.current + 1
      })
      request({
        url: '/agent/withdraw/records',
        data: {
          pageNum: that.data.current,
        }
      }).then((res) => {
        if (res.data.code == 200) {
          wx.hideToast()
          that.setData({
            withdrawalList: that.data.withdrawalList.concat(res.data.data.records),
            current: res.data.data.current,
          })
        } else {
          wx.hideToast()

        }
      })
    }
  },



})